<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>mockmatchers_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_testing_mockmatchers_test.js.html">mockmatchers_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.testing.mockmatchersTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.testing.mockmatchersTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.dom&#39;);
<a name="line19"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line20"></a>goog.require(&#39;goog.testing.mockmatchers&#39;);
<a name="line21"></a>goog.require(&#39;goog.testing.mockmatchers.ArgumentMatcher&#39;);
<a name="line22"></a>
<a name="line23"></a>// A local reference to the mockmatchers namespace.
<a name="line24"></a>var matchers = goog.testing.mockmatchers;
<a name="line25"></a>
<a name="line26"></a>// Simple classes to test the InstanceOf matcher.
<a name="line27"></a>var foo = function() {};
<a name="line28"></a>var bar = function() {};
<a name="line29"></a>
<a name="line30"></a>// Simple class to test adding error messages to
<a name="line31"></a>// MockExpectation objects
<a name="line32"></a>function MockMock() {
<a name="line33"></a>  this.errorMessages = [];
<a name="line34"></a>}
<a name="line35"></a>
<a name="line36"></a>var mockExpect = null;
<a name="line37"></a>
<a name="line38"></a>MockMock.prototype.addErrorMessage = function(msg) {
<a name="line39"></a>  this.errorMessages.push(msg);
<a name="line40"></a>};
<a name="line41"></a>
<a name="line42"></a>
<a name="line43"></a>MockMock.prototype.getErrorMessageCount = function() {
<a name="line44"></a>  return this.errorMessages.length;
<a name="line45"></a>};
<a name="line46"></a>
<a name="line47"></a>
<a name="line48"></a>function setUp() {
<a name="line49"></a>  mockExpect = new MockMock();
<a name="line50"></a>}
<a name="line51"></a>
<a name="line52"></a>
<a name="line53"></a>function testNoMatchName() {
<a name="line54"></a>  // A matcher that does not fill in the match name
<a name="line55"></a>  var matcher = new goog.testing.mockmatchers.ArgumentMatcher(goog.isString);
<a name="line56"></a>
<a name="line57"></a>  // Make sure the lack of match name doesn&#39;t affect the ability
<a name="line58"></a>  // to return True/False
<a name="line59"></a>  assertTrue(matcher.matches(&#39;hello&#39;));
<a name="line60"></a>  assertFalse(matcher.matches(123));
<a name="line61"></a>
<a name="line62"></a>  // Make sure we handle the lack of a match name
<a name="line63"></a>  assertFalse(matcher.matches(456, mockExpect));
<a name="line64"></a>  assertEquals(1, mockExpect.errorMessages.length);
<a name="line65"></a>  assertEquals(&#39;Expected: missing mockmatcher description &#39; +
<a name="line66"></a>      &#39;but was: &lt;456&gt; (Number)&#39;, mockExpect.errorMessages[0]);
<a name="line67"></a>}
<a name="line68"></a>
<a name="line69"></a>
<a name="line70"></a>function testInstanceOf() {
<a name="line71"></a>  var matcher = new matchers.InstanceOf(foo);
<a name="line72"></a>  assertTrue(matcher.matches(new foo()));
<a name="line73"></a>  assertFalse(matcher.matches(new bar()));
<a name="line74"></a>
<a name="line75"></a>  assertFalse(matcher.matches(new bar(), mockExpect));
<a name="line76"></a>  assertEquals(1, mockExpect.errorMessages.length);
<a name="line77"></a>  assertEquals(&#39;Expected: instanceOf() &#39; +
<a name="line78"></a>      &#39;but was: &lt;[object Object]&gt; (Object)&#39;,
<a name="line79"></a>      mockExpect.errorMessages[0]);
<a name="line80"></a>}
<a name="line81"></a>
<a name="line82"></a>
<a name="line83"></a>function testTypeOf() {
<a name="line84"></a>  var matcher = new matchers.TypeOf(&#39;number&#39;);
<a name="line85"></a>  assertTrue(matcher.matches(1));
<a name="line86"></a>  assertTrue(matcher.matches(2));
<a name="line87"></a>  assertFalse(matcher.matches(&#39;test&#39;));
<a name="line88"></a>
<a name="line89"></a>  assertFalse(matcher.matches(true, mockExpect));
<a name="line90"></a>  assertEquals(1, mockExpect.errorMessages.length);
<a name="line91"></a>  assertEquals(&#39;Expected: typeOf(number) but was: &lt;true&gt; (Boolean)&#39;,
<a name="line92"></a>      mockExpect.errorMessages[0]);
<a name="line93"></a>}
<a name="line94"></a>
<a name="line95"></a>
<a name="line96"></a>function testRegexpMatch() {
<a name="line97"></a>  var matcher = new matchers.RegexpMatch(/^cho[dtp]/);
<a name="line98"></a>  assertTrue(matcher.matches(&#39;chodhop&#39;));
<a name="line99"></a>  assertTrue(matcher.matches(&#39;chopper&#39;));
<a name="line100"></a>  assertFalse(matcher.matches(&#39;chocolate&#39;));
<a name="line101"></a>  assertFalse(matcher.matches(null));
<a name="line102"></a>
<a name="line103"></a>  assertFalse(matcher.matches(&#39;an anger&#39;, mockExpect));
<a name="line104"></a>  assertEquals(1, mockExpect.errorMessages.length);
<a name="line105"></a>  assertEquals(&#39;Expected: match(/^cho[dtp]/) but was: &lt;an anger&gt; (String)&#39;,
<a name="line106"></a>      mockExpect.errorMessages[0]);
<a name="line107"></a>}
<a name="line108"></a>
<a name="line109"></a>
<a name="line110"></a>function testObjectEquals() {
<a name="line111"></a>  // Test a simple match.
<a name="line112"></a>  var simpleMatcher = new matchers.ObjectEquals({name: &#39;Bob&#39;, age: 42});
<a name="line113"></a>  assertTrue(simpleMatcher.matches({name: &#39;Bob&#39;, age: 42}, mockExpect));
<a name="line114"></a>  assertEquals(0, mockExpect.getErrorMessageCount());
<a name="line115"></a>  expectObjectEqualsFailure(simpleMatcher, {name: &#39;Bill&#39;, age: 42},
<a name="line116"></a>      &#39;name: Expected &lt;Bob&gt; (String) but was &lt;Bill&gt; (String)&#39;);
<a name="line117"></a>  expectObjectEqualsFailure(simpleMatcher, {name: &#39;Bob&#39;, age: 21},
<a name="line118"></a>      &#39;age: Expected &lt;42&gt; (Number) but was &lt;21&gt; (Number)&#39;);
<a name="line119"></a>  expectObjectEqualsFailure(simpleMatcher, {name: &#39;Bob&#39;},
<a name="line120"></a>      &#39;property age not present in actual Object&#39;);
<a name="line121"></a>  expectObjectEqualsFailure(simpleMatcher,
<a name="line122"></a>      {name: &#39;Bob&#39;, age: 42, country: &#39;USA&#39;},
<a name="line123"></a>      &#39;property country not present in expected Object&#39;);
<a name="line124"></a>
<a name="line125"></a>  // Multiple mismatches should include multiple messages.
<a name="line126"></a>  expectObjectEqualsFailure(simpleMatcher, {name: &#39;Jim&#39;, age: 36},
<a name="line127"></a>      &#39;name: Expected &lt;Bob&gt; (String) but was &lt;Jim&gt; (String)\n&#39; +
<a name="line128"></a>      &#39;   age: Expected &lt;42&gt; (Number) but was &lt;36&gt; (Number)&#39;);
<a name="line129"></a>}
<a name="line130"></a>
<a name="line131"></a>function testComplexObjectEquals() {
<a name="line132"></a>  var complexMatcher = new matchers.ObjectEquals(
<a name="line133"></a>      {a: &#39;foo&#39;, b: 2, c: [&#39;bar&#39;, 3], d: {sub1: &#39;baz&#39;, sub2: -1}});
<a name="line134"></a>  assertTrue(complexMatcher.matches(
<a name="line135"></a>      {a: &#39;foo&#39;, b: 2, c: [&#39;bar&#39;, 3], d: {sub1: &#39;baz&#39;, sub2: -1}}));
<a name="line136"></a>  expectObjectEqualsFailure(complexMatcher,
<a name="line137"></a>      {a: &#39;foo&#39;, b: 2, c: [&#39;bar&#39;, 3], d: {sub1: &#39;zap&#39;, sub2: -1}},
<a name="line138"></a>      &#39;sub1: Expected &lt;baz&gt; (String) but was &lt;zap&gt; (String)&#39;);
<a name="line139"></a>  expectObjectEqualsFailure(complexMatcher,
<a name="line140"></a>      {a: &#39;foo&#39;, b: 2, c: [&#39;bar&#39;, 6], d: {sub1: &#39;baz&#39;, sub2: -1}},
<a name="line141"></a>      &#39;c[1]: Expected &lt;3&gt; (Number) but was &lt;6&gt; (Number)&#39;);
<a name="line142"></a>}
<a name="line143"></a>
<a name="line144"></a>
<a name="line145"></a>function testSaveArgument() {
<a name="line146"></a>  var saveMatcher = new matchers.SaveArgument();
<a name="line147"></a>  assertTrue(saveMatcher.matches(42));
<a name="line148"></a>  assertEquals(42, saveMatcher.arg);
<a name="line149"></a>
<a name="line150"></a>  saveMatcher = new matchers.SaveArgument(goog.isString);
<a name="line151"></a>  assertTrue(saveMatcher.matches(&#39;test&#39;));
<a name="line152"></a>  assertEquals(&#39;test&#39;, saveMatcher.arg);
<a name="line153"></a>  assertFalse(saveMatcher.matches(17));
<a name="line154"></a>  assertEquals(17, saveMatcher.arg);
<a name="line155"></a>
<a name="line156"></a>  saveMatcher = new matchers.SaveArgument(new matchers.ObjectEquals({
<a name="line157"></a>    value: &#39;value&#39;
<a name="line158"></a>  }));
<a name="line159"></a>  assertTrue(saveMatcher.matches({ value: &#39;value&#39; }));
<a name="line160"></a>  assertEquals(&#39;value&#39;, saveMatcher.arg.value);
<a name="line161"></a>  assertFalse(saveMatcher.matches(&#39;test&#39;));
<a name="line162"></a>  assertEquals(&#39;test&#39;, saveMatcher.arg);
<a name="line163"></a>}
<a name="line164"></a>
<a name="line165"></a>
<a name="line166"></a>function testIsArray() {
<a name="line167"></a>  assertTrue(matchers.isArray.matches([]));
<a name="line168"></a>  assertTrue(matchers.isArray.matches(new Array()));
<a name="line169"></a>  assertFalse(matchers.isArray.matches(&#39;test&#39;));
<a name="line170"></a>
<a name="line171"></a>  assertFalse(matchers.isArray.matches({}, mockExpect));
<a name="line172"></a>  assertEquals(1, mockExpect.errorMessages.length);
<a name="line173"></a>  assertEquals(&#39;Expected: isArray but was: &lt;[object Object]&gt; (Object)&#39;,
<a name="line174"></a>      mockExpect.errorMessages[0]);
<a name="line175"></a>}
<a name="line176"></a>
<a name="line177"></a>
<a name="line178"></a>function testIsArrayLike() {
<a name="line179"></a>  var nodeList = (function() {
<a name="line180"></a>    var div = document.createElement(&#39;div&#39;);
<a name="line181"></a>    div.appendChild(document.createElement(&#39;p&#39;));
<a name="line182"></a>    div.appendChild(document.createElement(&#39;p&#39;));
<a name="line183"></a>    return div.getElementsByTagName(&#39;div&#39;);
<a name="line184"></a>  })();
<a name="line185"></a>
<a name="line186"></a>  assertTrue(matchers.isArrayLike.matches([]));
<a name="line187"></a>  assertTrue(matchers.isArrayLike.matches(new Array()));
<a name="line188"></a>  assertTrue(matchers.isArrayLike.matches(nodeList));
<a name="line189"></a>  assertFalse(matchers.isArrayLike.matches(&#39;test&#39;));
<a name="line190"></a>
<a name="line191"></a>  assertFalse(matchers.isArrayLike.matches(3, mockExpect));
<a name="line192"></a>  assertEquals(1, mockExpect.errorMessages.length);
<a name="line193"></a>  assertEquals(&#39;Expected: isArrayLike but was: &lt;3&gt; (Number)&#39;,
<a name="line194"></a>      mockExpect.errorMessages[0]);
<a name="line195"></a>}
<a name="line196"></a>
<a name="line197"></a>
<a name="line198"></a>function testIsDateLike() {
<a name="line199"></a>  assertTrue(matchers.isDateLike.matches(new Date()));
<a name="line200"></a>  assertFalse(matchers.isDateLike.matches(&#39;test&#39;));
<a name="line201"></a>
<a name="line202"></a>  assertFalse(matchers.isDateLike.matches(&#39;test&#39;, mockExpect));
<a name="line203"></a>  assertEquals(1, mockExpect.errorMessages.length);
<a name="line204"></a>  assertEquals(&#39;Expected: isDateLike but was: &lt;test&gt; (String)&#39;,
<a name="line205"></a>      mockExpect.errorMessages[0]);
<a name="line206"></a>}
<a name="line207"></a>
<a name="line208"></a>
<a name="line209"></a>function testIsString() {
<a name="line210"></a>  assertTrue(matchers.isString.matches(&#39;a&#39;));
<a name="line211"></a>  assertTrue(matchers.isString.matches(&#39;b&#39;));
<a name="line212"></a>  assertFalse(matchers.isString.matches(null));
<a name="line213"></a>
<a name="line214"></a>  assertFalse(matchers.isString.matches(null, mockExpect));
<a name="line215"></a>  assertEquals(1, mockExpect.errorMessages.length);
<a name="line216"></a>  assertEquals(&#39;Expected: isString but was: &lt;null&gt;&#39;,
<a name="line217"></a>      mockExpect.errorMessages[0]);
<a name="line218"></a>}
<a name="line219"></a>
<a name="line220"></a>
<a name="line221"></a>function testIsBoolean() {
<a name="line222"></a>  assertTrue(matchers.isBoolean.matches(true));
<a name="line223"></a>  assertTrue(matchers.isBoolean.matches(false));
<a name="line224"></a>  assertFalse(matchers.isBoolean.matches(null));
<a name="line225"></a>
<a name="line226"></a>  assertFalse(matchers.isBoolean.matches([], mockExpect));
<a name="line227"></a>  assertEquals(1, mockExpect.errorMessages.length);
<a name="line228"></a>  assertEquals(&#39;Expected: isBoolean but was: &lt;&gt; (Array)&#39;,
<a name="line229"></a>      mockExpect.errorMessages[0]);
<a name="line230"></a>}
<a name="line231"></a>
<a name="line232"></a>
<a name="line233"></a>function testIsNumber() {
<a name="line234"></a>  assertTrue(matchers.isNumber.matches(-1));
<a name="line235"></a>  assertTrue(matchers.isNumber.matches(1));
<a name="line236"></a>  assertTrue(matchers.isNumber.matches(1.25));
<a name="line237"></a>  assertFalse(matchers.isNumber.matches(null));
<a name="line238"></a>
<a name="line239"></a>  assertFalse(matchers.isNumber.matches(&#39;hello&#39;, mockExpect));
<a name="line240"></a>  assertEquals(1, mockExpect.errorMessages.length);
<a name="line241"></a>  assertEquals(&#39;Expected: isNumber but was: &lt;hello&gt; (String)&#39;,
<a name="line242"></a>      mockExpect.errorMessages[0]);
<a name="line243"></a>}
<a name="line244"></a>
<a name="line245"></a>
<a name="line246"></a>function testIsFunction() {
<a name="line247"></a>  assertTrue(matchers.isFunction.matches(function() {}));
<a name="line248"></a>  assertFalse(matchers.isFunction.matches(&#39;test&#39;));
<a name="line249"></a>
<a name="line250"></a>  assertFalse(matchers.isFunction.matches({}, mockExpect));
<a name="line251"></a>  assertEquals(1, mockExpect.errorMessages.length);
<a name="line252"></a>  assertEquals(&#39;Expected: isFunction but was: &lt;[object Object]&gt; (Object)&#39;,
<a name="line253"></a>      mockExpect.errorMessages[0]);
<a name="line254"></a>}
<a name="line255"></a>
<a name="line256"></a>
<a name="line257"></a>function testIsObject() {
<a name="line258"></a>  assertTrue(matchers.isObject.matches({}));
<a name="line259"></a>  assertTrue(matchers.isObject.matches(new Object()));
<a name="line260"></a>  assertTrue(matchers.isObject.matches(new function() {}));
<a name="line261"></a>  assertTrue(matchers.isObject.matches([]));
<a name="line262"></a>  assertTrue(matchers.isObject.matches(new Array()));
<a name="line263"></a>  assertTrue(matchers.isObject.matches(function() {}));
<a name="line264"></a>  assertFalse(matchers.isObject.matches(null));
<a name="line265"></a>
<a name="line266"></a>  assertFalse(matchers.isObject.matches(1234, mockExpect));
<a name="line267"></a>  assertEquals(1, mockExpect.errorMessages.length);
<a name="line268"></a>  assertEquals(&#39;Expected: isObject but was: &lt;1234&gt; (Number)&#39;,
<a name="line269"></a>      mockExpect.errorMessages[0]);
<a name="line270"></a>}
<a name="line271"></a>
<a name="line272"></a>
<a name="line273"></a>function testIsNodeLike() {
<a name="line274"></a>  assertFalse(matchers.isNodeLike.matches({}));
<a name="line275"></a>  assertFalse(matchers.isNodeLike.matches(1));
<a name="line276"></a>  assertFalse(matchers.isNodeLike.matches(function() {}));
<a name="line277"></a>  assertFalse(matchers.isNodeLike.matches(false));
<a name="line278"></a>  assertTrue(matchers.isNodeLike.matches(document.body));
<a name="line279"></a>  assertTrue(matchers.isNodeLike.matches(goog.dom.getElement(&#39;someDiv&#39;)));
<a name="line280"></a>
<a name="line281"></a>  assertFalse(matchers.isNodeLike.matches(&#39;test&#39;, mockExpect));
<a name="line282"></a>  assertEquals(1, mockExpect.errorMessages.length);
<a name="line283"></a>  assertEquals(&#39;Expected: isNodeLike but was: &lt;test&gt; (String)&#39;,
<a name="line284"></a>      mockExpect.errorMessages[0]);
<a name="line285"></a>}
<a name="line286"></a>
<a name="line287"></a>
<a name="line288"></a>function testIgnoreArgumentsMatcher() {
<a name="line289"></a>  // ignoreArgument always returns true:
<a name="line290"></a>  assertTrue(matchers.ignoreArgument.matches());
<a name="line291"></a>  assertTrue(matchers.ignoreArgument.matches(356));
<a name="line292"></a>  assertTrue(matchers.ignoreArgument.matches(&#39;str&#39;));
<a name="line293"></a>  assertTrue(matchers.ignoreArgument.matches([&#39;array&#39;, 123, false]));
<a name="line294"></a>  assertTrue(matchers.ignoreArgument.matches({&#39;map&#39;: 1, key2: &#39;value2&#39;}));
<a name="line295"></a>}
<a name="line296"></a>
<a name="line297"></a>
<a name="line298"></a>function testFlexibleArrayMatcher() {
<a name="line299"></a>  // Test that basic lists are verified properly.
<a name="line300"></a>  var a1 = [1, &#39;test&#39;];
<a name="line301"></a>  var a2 = [1, &#39;test&#39;];
<a name="line302"></a>  var a3 = [1, &#39;test&#39;, &#39;extra&#39;];
<a name="line303"></a>  assertTrue(matchers.flexibleArrayMatcher(a1, a2));
<a name="line304"></a>  assertFalse(matchers.flexibleArrayMatcher(a1, a3));
<a name="line305"></a>
<a name="line306"></a>  // Test that basic lists with basic class instances are verified properly.
<a name="line307"></a>  var instance = new foo();
<a name="line308"></a>  a1 = [1, &#39;test&#39;, instance];
<a name="line309"></a>  a2 = [1, &#39;test&#39;, instance];
<a name="line310"></a>  a3 = [1, &#39;test&#39;, new foo()];
<a name="line311"></a>  assertTrue(matchers.flexibleArrayMatcher(a1, a2));
<a name="line312"></a>  assertTrue(matchers.flexibleArrayMatcher(a1, a3));
<a name="line313"></a>
<a name="line314"></a>  // Create an argument verifier that returns a consistent value.
<a name="line315"></a>  var verifyValue = true;
<a name="line316"></a>  var argVerifier = function() {};
<a name="line317"></a>  goog.inherits(argVerifier, matchers.ArgumentMatcher);
<a name="line318"></a>  argVerifier.prototype.matches = function(arg) {
<a name="line319"></a>    return verifyValue;
<a name="line320"></a>  };
<a name="line321"></a>
<a name="line322"></a>  // Test that the arguments are always verified when the verifier returns
<a name="line323"></a>  // true.
<a name="line324"></a>  a1 = [1, &#39;test&#39;, new argVerifier()];
<a name="line325"></a>  a2 = [1, &#39;test&#39;, &#39;anything&#39;];
<a name="line326"></a>  a3 = [1, &#39;test&#39;, 12345];
<a name="line327"></a>  assertTrue(matchers.flexibleArrayMatcher(a1, a2));
<a name="line328"></a>  assertTrue(matchers.flexibleArrayMatcher(a1, a3));
<a name="line329"></a>
<a name="line330"></a>  // Now test the case when then verifier returns false.
<a name="line331"></a>  verifyValue = false;
<a name="line332"></a>  assertFalse(matchers.flexibleArrayMatcher(a1, a2));
<a name="line333"></a>  assertFalse(matchers.flexibleArrayMatcher(a1, a3));
<a name="line334"></a>
<a name="line335"></a>  // And test we report errors back up via the opt_expectation
<a name="line336"></a>  assertFalse(matchers.flexibleArrayMatcher(a2, a3, mockExpect));
<a name="line337"></a>  assertEquals(1, mockExpect.errorMessages.length);
<a name="line338"></a>  assertEquals(
<a name="line339"></a>      &#39;Expected &lt;anything&gt; (String) but was &lt;12345&gt; (Number)\n&#39; +
<a name="line340"></a>      &#39;    Expected &lt;anything&gt; (String) but was &lt;12345&gt; (Number)&#39;,
<a name="line341"></a>      mockExpect.errorMessages[0]);
<a name="line342"></a>
<a name="line343"></a>  // And test we report errors found via the matcher
<a name="line344"></a>  a1 = [1, goog.testing.mockmatchers.isString];
<a name="line345"></a>  a2 = [1, &#39;test string&#39;];
<a name="line346"></a>  a3 = [1, null];
<a name="line347"></a>  assertTrue(matchers.flexibleArrayMatcher(a1, a2, mockExpect));
<a name="line348"></a>  assertFalse(matchers.flexibleArrayMatcher(a1, a3, mockExpect));
<a name="line349"></a>  // Old error is still there
<a name="line350"></a>  assertEquals(2, mockExpect.errorMessages.length);
<a name="line351"></a>  assertEquals(
<a name="line352"></a>      &#39;Expected &lt;anything&gt; (String) but was &lt;12345&gt; (Number)\n&#39; +
<a name="line353"></a>      &#39;    Expected &lt;anything&gt; (String) but was &lt;12345&gt; (Number)&#39;,
<a name="line354"></a>      mockExpect.errorMessages[0]);
<a name="line355"></a>  // plus the new error...
<a name="line356"></a>  assertEquals(&#39;Expected: isString but was: &lt;null&gt;&#39;,
<a name="line357"></a>      mockExpect.errorMessages[1]);
<a name="line358"></a>}
<a name="line359"></a>
<a name="line360"></a>
<a name="line361"></a>/**
<a name="line362"></a> * Utility method for checking for an ObjectEquals match failure.  Checks that
<a name="line363"></a> * the expected error message was included in the error messages appended to
<a name="line364"></a> * the expectation object.
<a name="line365"></a> * @param {goog.testing.mockmatchers.ArgumentMatcher.ObjectEquals} matcher
<a name="line366"></a> *     The matcher to test against.
<a name="line367"></a> * @param {Object} matchObject The object to compare.
<a name="line368"></a> * @param {string=} opt_errorMsg The deep object comparison failure message
<a name="line369"></a> *     to check for.
<a name="line370"></a> */
<a name="line371"></a>function expectObjectEqualsFailure(matcher, matchObject, opt_errorMsg) {
<a name="line372"></a>  mockExpect.errorMessages = [];
<a name="line373"></a>  assertFalse(matcher.matches(matchObject, mockExpect));
<a name="line374"></a>  assertNotEquals(0, mockExpect.getErrorMessageCount());
<a name="line375"></a>  if (opt_errorMsg) {
<a name="line376"></a>    assertContains(opt_errorMsg, mockExpect.errorMessages[0]);
<a name="line377"></a>  }
<a name="line378"></a>}
</pre>


</body>
</html>
